;---------------------------------------------------------------------
; dkfunctiontable.S - table of function names and handler functions for DK-BASIC - Chris Gerlinsky, 2009
;---------------------------------------------------------------------

.nolist
#include <avr/io.h>	// Include device specific definitions.
.list


;---------------------------------------------------------------------
; FLASH - constants (in code segment)

.section .text

.global dkfunctiontable
dkfunctiontable:
.string "asc"							; ASC() function
.word	dkfunction_asc
.string "hex"							; HEX$() function
.word	dkfunction_hex
.string "chr"							; CHR$() function
.word	dkfunction_chr
.string "peek"							; PEEK() function
.word	dkfunction_peek
.string "bit"							; BIT() function *DKBASIC+
.word	dkfunction_bit
.string "test"							; TEST() function *DKBASIC+
.word	dkfunction_test
.string "inkey"							; INKEY$ function
.word	dkfunction_inkey
.string "csrlin"						; CSRLIN function
.word	dkfunction_csrlin
.string "pos"							; POS() function
.word	dkfunction_pos
.string "eof"							; EOF() function
.word	dkfunction_eof
.string "input"							; INPUT$() function
.word	dkfunction_input
.string "loc"							; LOC() function
.word	dkfunction_loc
.string "string"						; STRING$() function
.word	dkfunction_string
.string "sysinfo"						; SYSINFO$() function
.word	dkfunction_sysinfo
.string "len"                           ; LEN() function
.word   dkfunction_len

.byte	0								; end interp_keywords with an empty string (NULL)


.align 2								; code must be aligned on word boundary


;---------------------------------------------------------------------
; FLASH - code

;---------------------------------------------------------------------
; dkfindfunction
; r25:r24 in = ptr to string in ram
; r25:r24 out = ptr to statment handler function
; note: side effect: string is converted to lowercase

.func dkfindfunction
.global dkfindfunction
dkfindfunction:
	ldi		r23, hi8(dkfunctiontable)	; dkfunctiontable in FLASH is a list of names and matching functions
	ldi		r22, lo8(dkfunctiontable)

	call	dksearchtable

	lsr		r25							; shift address to the right (adjust from byte address to word address)
	ror		r24

	ret
.endfunc


;---------------------------------------------------------------------

